#ifndef __DEVICECONTROL_H_
#define __DEVICECONTROL_H_
#include "StreamRecord.h"
#include "x_timer.h"

class CDeviceControl
{
public:
	CDeviceControl();
	~CDeviceControl();

public:
	///录像控制接口
	int StartRecord(const char *pResid, int nDuration, char *pFileName = NULL);
	int StopRecord(const char *pResid);

	///预录控制接口
	int StartPreRecord(const char *pResid, int nTimeLen);
	int StopPreRecord(const char *pResid);

	///云台控制接口
	int PtzControl(const char *pResid, int nCmd, int nParam);

	///查询DVR录像文件列表
	//int EnumFileList(const char *pResid, time_t beginTime, time_t endTime, sublist &fileList);

private:
	/*static int OnMessage(Message* msg, int msgtype, void* pUser)
	{
		CDeviceControl *pThis = static_cast<CDeviceControl *>(pUser);
		if (pThis == NULL)
			return J_UNKOWN;

		return pThis->ProcessMsg(msg, msgtype);
	}
	int ProcessMsg(Message* msg, int msgtype);*/

	static void TimerThread(unsigned long ulUser)
	{
		CDeviceControl *pThis = static_cast<CDeviceControl *>((void *)ulUser);
		if (pThis != NULL)
			pThis->OnTimer();
	}
	void OnTimer();

	static void PreTimerThread(unsigned long ulUser)
	{
		CDeviceControl *pThis = static_cast<CDeviceControl *>((void *)ulUser);
		if (pThis != NULL)
			pThis->OnPreTimer();
	}
	void OnPreTimer();

private:
	struct RecordInfo
	{
		CStreamRecord *pRecord;
		bool bPreRecord;
		int nCount;
		int nPreCount;
	};
	std::map<std::string, RecordInfo> m_recordMap;	//Resid 与 VideoRecord对象的映射关系

	J_OS::CTimer m_timer;
	struct DurationInfo
	{
		int curTimes;
		int duration;
		//Message *pMessage;
		DurationInfo()
		{
			curTimes = 0;
			duration = 0;
			//pMessage = NULL;
		}
	};
	std::map<std::string, DurationInfo> m_recordDurationMap;	//Resid 与 录像时的映射关系


	J_OS::CTimer m_preTimer;
	struct PreInfo
	{
		int duration;
		bool flag;
		PreInfo()
		{
			duration = 0;
			flag = false;
		}
	};
	typedef std::map<std::string, PreInfo> PreMap;
	PreMap m_preMap;
	bool m_bPreReady;
};
#endif //__DEVICECONTROL_H_
